# encoding:utf-8

from flask import Flask
from flask_cors import CORS
from flask_restful import Api
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor

from common.models import db, cache
from cloud_info_flask.account.user import user_bp
from cloud_info_flask.account.oauth_user import oauth2_bp
from cloud_info_flask.course.course import course_bp
from cloud_info_flask.comment.comment import comment_bp
from cloud_info_flask.pay.pay import pay_bp

from cloud_info_flask.book_manage.book import book_bp
from common.utils.middlewares import jwt_authentication
from common.cron_task.news_task import update_recommend_list
# from celery_task.main import celery_app
from logs.logs import setup_log


def cron_test():
    print('这是测试定时任务')


def create_flask_app(config):
    app = Flask(__name__)
    app.config.from_object(config)
    app.before_request(jwt_authentication)
    db.init_app(app)
    cache.init_app(app)
    app.register_blueprint(user_bp)

    setup_log('testing')
    cors = CORS(app, resources={r"/*/*": {"origins": "*"}})


    api = Api(app)
    return app
